﻿using NightskyMimic.Domain;
using NightskyMimic.Util;
using System.Collections.Generic;
using System.Linq;

namespace NightskyMimic.Core
{
    public class RandomActions : Strategy
    {
        public List<Attack> GenerateAttackActions(Player player, Player opponent)
        {
            List<Attack> result = new List<Attack>();

            List<Creature> creatures = player.Zone.Creatures.Where(x => !x.Tapped).ToList();

            foreach (Creature c in creatures) 
                if (Unicorn.Dash(0, 10) > 5)
                    result.Add(new Attack(c));

            return result;
        }

        public List<Block> GenerateBlockActions(Player player, Player opponent, List<Attack> attack)
        {
            List<Block> result = new List<Block>();

            if (attack.Count > 0)
            {
                List<Creature> creatures = player.Zone.Creatures.Where(x => !x.Tapped).ToList();

                foreach (Creature c in creatures)
                {
                    //each creature able to block has a chance of 50% to block a random attacker
                    if (Unicorn.Dash(0, 10) < 5)
                    {
                        int attacker = Unicorn.Dash(0, attack.Count);
                        result.Add(new Block(c, attack[attacker].Target));
                    }
                }
            }

            return result;
        }
    }
}
